﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Settings="clr-namespace:MoPlus.SolutionBuilder.WpfClient.Library;assembly=MoPlus.SolutionBuilder.WpfClient"
                   xmlns:lib="clr-namespace:MoPlus.SolutionBuilder.WpfClient.Library">

	<LinearGradientBrush x:Key="DiagramNormalBorderBrush" EndPoint="0.5,0" StartPoint="0.5,1">
		<GradientStop Color="#FF84B2D4" />
		<GradientStop Color="#FFADC7DE" Offset="1" />
	</LinearGradientBrush>

	<LinearGradientBrush x:Key="DiagramPressedBorderBrush" EndPoint="0.5,0" StartPoint="0.5,1">
		<GradientStop Color="#CC517FA1" />
		<GradientStop Color="#CC7A94AB" Offset="1" />
	</LinearGradientBrush>

	<Style TargetType="{x:Type lib:ZoomBox}">

		<Style.Resources>
			<ResourceDictionary>
				<ResourceDictionary.MergedDictionaries>
					<ResourceDictionary Source="../Resources/Theme.xaml" />
				</ResourceDictionary.MergedDictionaries>
			</ResourceDictionary>
		</Style.Resources>

		<Setter Property="SnapsToDevicePixels" Value="true" />
		<Setter Property="HorizontalOffset" Value="{Binding HorizontalOffset, Mode=TwoWay}" />
		<Setter Property="VerticalOffset" Value="{Binding VerticalOffset, Mode=TwoWay}" />
		<Setter Property="Scale" Value="{Binding Scale, Mode=TwoWay}" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type lib:ZoomBox}">
					<Border BorderBrush="{StaticResource NormalBorderBrush}" BorderThickness="1" Padding="0" Height="140">
						<Grid>
							<Grid.RowDefinitions>
								<RowDefinition Height="Auto" />
								<RowDefinition Height="*" />
							</Grid.RowDefinitions>
							<Grid Grid.Row="0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Background="{StaticResource ControlDarkBackgroundBrush}">
								<Grid.ColumnDefinitions>
									<ColumnDefinition Width="*" />
									<ColumnDefinition Width="40" />
								</Grid.ColumnDefinitions>
								<Slider Grid.Row="0" Name="PART_ZoomSlider" VerticalAlignment="Center" HorizontalAlignment="Stretch" Margin="0" Ticks="25,50,75,100,125,150,200,300,400,500" Minimum="25" Maximum="500" Value="100" IsSnapToTickEnabled="True" IsMoveToPointEnabled="False" />
								<TextBlock Text="{Binding ElementName=PART_ZoomSlider, Path=Value}" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0,0,14,0" />
								<TextBlock Text="%" Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="1,0,2,0" />
							</Grid>
							<Grid Grid.Row="1" Background="{StaticResource UnusedBackgroundBrush}" >
								<Canvas Margin="4,4,7,4" Name="PART_ZoomCanvas" RenderTransformOrigin="0.5,0.5">
									<Canvas.Background>
										<VisualBrush Stretch="Uniform" Visual="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ScrollViewer.Content}" />
									</Canvas.Background>
									<Thumb Name="PART_ZoomThumb" Cursor="SizeAll">
										<Thumb.Style>
											<Style TargetType="Thumb">
												<Setter Property="Template">
													<Setter.Value>
														<ControlTemplate TargetType="Thumb">
															<Rectangle StrokeThickness="1" Margin="0,0,1,1" Stroke="Black" Fill="Transparent" />
														</ControlTemplate>
													</Setter.Value>
												</Setter>
											</Style>
										</Thumb.Style>
									</Thumb>
								</Canvas>
							</Grid>
						</Grid>
					</Border>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<!-- Connector Style -->
	<Style TargetType="{x:Type lib:Connector}">
		<Setter Property="Width" Value="8"/>
		<Setter Property="Height" Value="8"/>
		<Setter Property="Cursor" Value="Cross"/>
		<Setter Property="SnapsToDevicePixels" Value="true"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type lib:Connector}">
					<Grid>
						<!-- transparent extra space makes connector easier to hit -->
						<Rectangle Fill="Transparent" Margin="-2"/>
						<Rectangle Fill="Lavender" StrokeThickness="1" Stroke="#AA000080"/>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<!-- ConnectorDecoratorTemplate Default Template -->
	<ControlTemplate x:Key="ConnectorDecoratorTemplate" TargetType="{x:Type Control}">
		<Grid Margin="-5">
			<lib:Connector Orientation="Left" VerticalAlignment="Center" HorizontalAlignment="Left"/>
			<lib:Connector Orientation="Top" VerticalAlignment="Top" HorizontalAlignment="Center"/>
			<lib:Connector Orientation="Right" VerticalAlignment="Center" HorizontalAlignment="Right"/>
			<lib:Connector Orientation="Bottom" VerticalAlignment="Bottom" HorizontalAlignment="Center"/>
		</Grid>
	</ControlTemplate>

	<!-- ResizeThumb Style -->
	<Style TargetType="{x:Type lib:ResizeThumb}">
		<Setter Property="SnapsToDevicePixels" Value="true"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type lib:ResizeThumb}">
					<Grid>
						<!-- transparent extra space makes connector easier to hit -->
						<Rectangle Fill="Transparent" Margin="-10"/>
						<Rectangle Fill="{StaticResource DiagramPressedBorderBrush}" StrokeThickness="3" Stroke="{StaticResource DiagramPressedBorderBrush}"/>
					</Grid>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<!-- ResizeDecorator Default Template -->
	<ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
		<Grid Opacity="0.7" SnapsToDevicePixels="true">
			<lib:ResizeThumb Height="3" Cursor="SizeNS" VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
			<lib:ResizeThumb Width="3" Cursor="SizeWE" VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
			<lib:ResizeThumb Width="3" Cursor="SizeWE" VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
			<lib:ResizeThumb Height="3" Cursor="SizeNS" VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
			<lib:ResizeThumb Width="3" Height="3" Cursor="SizeNWSE" VerticalAlignment="Top" HorizontalAlignment="Left"/>
			<lib:ResizeThumb Width="3" Height="3" Cursor="SizeNESW" VerticalAlignment="Top" HorizontalAlignment="Right"/>
			<lib:ResizeThumb Width="3" Height="3" Cursor="SizeNESW" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
			<lib:ResizeThumb Width="3" Height="3" Cursor="SizeNWSE" VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
		</Grid>
	</ControlTemplate>

	<!-- DragThumb Default Template -->
	<Style TargetType="{x:Type lib:DragThumb}">
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type lib:DragThumb}">
					<Rectangle Fill="Transparent"/>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<!-- DesignerItem Style -->
	<Style TargetType="{x:Type lib:DesignerItem}">
		<Setter Property="MinWidth" Value="25"/>
		<Setter Property="MinHeight" Value="25"/>
		<Setter Property="SnapsToDevicePixels" Value="True"/>
		<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type lib:DesignerItem}">
					<Grid>
						<Grid.BitmapEffect>
							<DropShadowBitmapEffect Color="Gray" Direction="320" ShadowDepth="10" Softness=".5" Opacity="0.2"/>
						</Grid.BitmapEffect>
						<!-- PART_DragThumb -->
						<lib:DragThumb x:Name="PART_DragThumb" Cursor="SizeAll"/>
						<!-- PART_ResizeDecorator -->
						<Control x:Name="PART_ResizeDecorator" Visibility="Collapsed" Template="{StaticResource ResizeDecoratorTemplate}"/>
						<!-- PART_ContentPresenter -->
						<ContentPresenter x:Name="PART_ContentPresenter" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Content="{TemplateBinding ContentControl.Content}" Margin="{TemplateBinding ContentControl.Padding}"/>
						<!-- PART_ConnectorDecorator
						<Control x:Name="PART_ConnectorDecorator" Visibility="Hidden" Template="{StaticResource ConnectorDecoratorTemplate}"/>
						-->
					</Grid>
					<ControlTemplate.Triggers>
						<DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsSelected}">
							<Setter TargetName="PART_ResizeDecorator" Property="Visibility" Value="Visible"/>
						</DataTrigger>
						<!--
						<Trigger Property="IsMouseOver" Value="true">
							<Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/>
						</Trigger>
						<DataTrigger Value="True" Binding="{Binding RelativeSource={RelativeSource Self},Path=IsDragConnectionOver}">
							<Setter TargetName="PART_ConnectorDecorator" Property="Visibility" Value="Visible"/>
						</DataTrigger>
						-->
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

	<Style TargetType="{x:Type lib:Connection}">
		<Style.Resources>
			<ResourceDictionary>
				<ResourceDictionary.MergedDictionaries>
					<ResourceDictionary Source="../Resources/Theme.xaml" />
				</ResourceDictionary.MergedDictionaries>
				<!-- Style for the ConnectorAdorner thumbs -->
				<Style x:Key="ConnectionAdornerThumbStyle" TargetType="{x:Type Thumb}">
					<Setter Property="Width" Value="12"/>
					<Setter Property="Height" Value="12"/>
					<Setter Property="SnapsToDevicePixels" Value="true"/>
					<Setter Property="RenderTransform">
						<Setter.Value>
							<TranslateTransform X="-6" Y="-6"/>
						</Setter.Value>
					</Setter>
					<Setter Property="Template">
						<Setter.Value>
							<ControlTemplate TargetType="{x:Type Thumb}">
								<Rectangle Fill="#AADCDCDC" Stroke="DodgerBlue" StrokeThickness="1" RadiusX="0" RadiusY="0"/>
							</ControlTemplate>
						</Setter.Value>
					</Setter>
				</Style>
				<!-- Arrow Grid Style -->
				<Style x:Key="ArrowGridStyle" TargetType="Grid">
					<Setter Property="Width" Value="10"/>
					<Setter Property="Height" Value="10"/>
					<Setter Property="RenderTransform">
						<Setter.Value>
							<TranslateTransform X="-5" Y="-5"/>
						</Setter.Value>
					</Setter>
				</Style>
				<!-- base style for all arrow shapes -->
				<Style x:Key="ArrowSymbolBaseStyle" TargetType="Path">
					<Setter Property="Fill" Value="{StaticResource NormalBorderBrush}"/>
					<Setter Property="Stretch" Value="Fill"/>
					<Style.Triggers>
						<DataTrigger Binding="{Binding IsSelected}" Value="True">
							<Setter Property="Fill" Value="{StaticResource DiagramPressedBorderBrush}" />
						</DataTrigger>
					</Style.Triggers>
				</Style>
				<!-- Arrow -->
				<Style x:Key="Arrow" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
					<Setter Property="Data" Value="M0,0 8,4 0,8 Z"/>
				</Style>
				<!-- DoubleArrow -->
				<Style x:Key="DoubleArrow" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
					<Setter Property="Data" Value="M0,0 8,4 0,8 0,4 -8,0 -8,8 0,4 Z"/>
				</Style>
				<!-- Diamond  -->
				<Style x:Key="Diamond" TargetType="Path" BasedOn="{StaticResource ArrowSymbolBaseStyle}">
					<Setter Property="Data" Value="M-5,0 0,-5 5,0 0,5 Z"/>
				</Style>
			</ResourceDictionary>
		</Style.Resources>

		<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
		<Setter Property="Margin" Value="-2" />
		<Setter Property="Padding" Value="12" />
		<Setter Property="SnapsToDevicePixels" Value="True"/>
		<Setter Property="Template">
			<Setter.Value>
				<ControlTemplate TargetType="{x:Type lib:Connection}">
					<Canvas DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}" >
						<Path StrokeThickness="10" Stroke="Transparent" IsHitTestVisible="True" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" StrokeDashArray="{Binding StrokeDashArray}" SnapsToDevicePixels="True" Data="{Binding PathGeometry}"/>
						<Path Name="PART_ConnectionPath" StrokeThickness="3" Stroke="{StaticResource NormalBorderBrush}" StrokeStartLineCap="Round" StrokeEndLineCap="Round" StrokeLineJoin="Round" StrokeDashArray="{Binding StrokeDashArray}" SnapsToDevicePixels="True" Data="{Binding PathGeometry}"/>
						<Grid Style="{StaticResource ArrowGridStyle}" Canvas.Left="{Binding AnchorPositionSource.X}" Canvas.Top="{Binding AnchorPositionSource.Y}">
							<Path Name="PART_SourceAnchorPath"/>
							<Grid.LayoutTransform>
								<RotateTransform Angle="{Binding AnchorAngleSource}"/>
							</Grid.LayoutTransform>
						</Grid>
						<Grid Style="{StaticResource ArrowGridStyle}" Canvas.Left="{Binding AnchorPositionSink.X}" Canvas.Top="{Binding AnchorPositionSink.Y}">
							<Path Name="PART_SinkAnchorPath"/>
							<Grid.LayoutTransform>
								<RotateTransform Angle="{Binding AnchorAngleSink}"/>
							</Grid.LayoutTransform>
						</Grid>

						<TextBlock Width="100" Height="35" Text="{Binding SourceLabel}"                       
						           Canvas.Left="{Binding SourceLabelPosition.X}"
						           Canvas.Top="{Binding SourceLabelPosition.Y}">
							<TextBlock.RenderTransform>
								<TranslateTransform X="5" Y="5"/>
							</TextBlock.RenderTransform>
						</TextBlock>
						<TextBlock Width="100" Height="35" Text="{Binding SinkLabel}"                       
						           Canvas.Left="{Binding SinkLabelPosition.X}"
						           Canvas.Top="{Binding SinkLabelPosition.Y}">
							<TextBlock.RenderTransform>
								<TranslateTransform X="5" Y="5"/>
							</TextBlock.RenderTransform>
						</TextBlock>

						<Canvas.BitmapEffect>
							<DropShadowBitmapEffect Color="Gray" Direction="320" ShadowDepth="5" Softness=".2" Opacity="0.2"/>
						</Canvas.BitmapEffect>
					</Canvas>
					<ControlTemplate.Triggers>
						<DataTrigger Value="Arrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
							<Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource Arrow}"/>
						</DataTrigger>
						<DataTrigger Value="DoubleArrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
							<Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource DoubleArrow}"/>
						</DataTrigger>
						<DataTrigger Value="Diamond" Binding="{Binding RelativeSource={RelativeSource Self},Path=SourceArrowSymbol}">
							<Setter TargetName="PART_SourceAnchorPath" Property="Style" Value="{StaticResource Diamond}"/>
						</DataTrigger>
						<DataTrigger Value="Arrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
							<Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource Arrow}"/>
						</DataTrigger>
						<DataTrigger Value="DoubleArrow" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
							<Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource DoubleArrow}"/>
						</DataTrigger>
						<DataTrigger Value="Diamond" Binding="{Binding RelativeSource={RelativeSource Self},Path=SinkArrowSymbol}">
							<Setter TargetName="PART_SinkAnchorPath" Property="Style" Value="{StaticResource Diamond}"/>
						</DataTrigger>
						<DataTrigger Binding="{Binding IsSelected}" Value="True">
							<Setter TargetName="PART_ConnectionPath" Property="Stroke" Value="{StaticResource DiagramPressedBorderBrush}" />
						</DataTrigger>
					</ControlTemplate.Triggers>
				</ControlTemplate>
			</Setter.Value>
		</Setter>
	</Style>

</ResourceDictionary>